#include "../include/HierarchicalConfiguration.h"
#include "../include/QtXmlConfigurationbuilder.h"

class MyNodeVisitor : public HierarchicalConfigurationNodeVisitor
{
public:
    MyNodeVisitor() : m_indent( 0 ), m_indentIncrement( 4 ) {}
    
    void visitBeforeChildren( HierarchicalConfigurationNode * node )
    {	
	for( int i = 0; i < m_indent; i++ )
	    printf( " " );
	if( node->isAttribute() )
	    printf( "AttributeNode - %s = %s \n", node->name().c_str(), node->value().c_str() );
	else
	    printf( "Node - %s = %s - Children: %d \n", 
		    node->name().c_str(), 
		    node->value().size() == 0 ? "Value Not Set" : node->value().c_str(), 
		    node->children().size() );

	m_indent += m_indentIncrement;
    }

    void visitAfterChildren( HierarchicalConfigurationNode * node )
    {
	m_indent -= m_indentIncrement;
    }

    bool terminate() 
    {
	return( false );
    }

    int m_indent, m_indentIncrement;
};

int main( int argc, char ** argv )
{
    QtXmlConfigurationBuilder configBuilder;

    configBuilder.run( "MySiteConf.xml" );

    configBuilder.m_root->visit( new MyNodeVisitor( ) );

    std::vector<HierarchicalConfigurationNode*> sites = configBuilder.m_root->subconfigurations( "Site" );
    qDebug( "Site.size() == %d", sites.size() );
    int numberOfCpus = sites[0]->subconfigurations( "NumberOfCPUs" )[0]->castValue<int>( 0 );
    qDebug( "NumberOfCpus == %d", numberOfCpus );
    delete configBuilder.m_root;

    return( 0 );
}
